﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Practices.Unity;
using Vit.Common;
using Vit.Common.Providers;
using Vit.Web.Models;
using Vit.Web.Providers;

namespace Vit.Mvc
{
    public class UnityViewEngine : WebFormViewEngine
    {
        private static readonly string[] _emptyLocations;

        static UnityViewEngine()
        {
            _emptyLocations = new string[0];
        }

        private UnityService<IMembershipProvider> membership;

        public UnityViewEngine(UnityService<IMembershipProvider> membership)
        {
            base.MasterLocationFormats = new string[] { 
                "~/Themes/{0}.master", 
                "~/Views/{1}/{0}.master", 
                "~/Views/Shared/{0}.master"
            };
            base.AreaMasterLocationFormats = new string[] { 
                "~/Areas/{2}/Themes/{0}.master", 
                "~/Areas/{2}/Views/{1}/{0}.master", 
                "~/Areas/{2}/Views/Shared/{0}.master", 
                "~/Themes/{0}.master",
                "~/Views/{1}/{0}.master", 
                "~/Views/Shared/{0}.master"
            };
            base.ViewLocationFormats = new string[] { 
                "~/Views/{1}/{0}.aspx", 
                "~/Views/{1}/{0}.ascx", 
                "~/Views/Shared/{0}.aspx", 
                "~/Views/Shared/{0}.ascx", 
                "~/Themes/{0}.aspx",
                "~/Themes/{0}.ascx"
            };
            base.AreaViewLocationFormats = new string[] { 
                "~/Areas/{2}/Views/{1}/{0}.aspx", 
                "~/Areas/{2}/Views/{1}/{0}.ascx", 
                "~/Areas/{2}/Views/Shared/{0}.aspx", 
                "~/Areas/{2}/Views/Shared/{0}.ascx", 
                "~/Areas/{2}/Themes/{0}.aspx", 
                "~/Areas/{2}/Themes/{0}.ascx", 
                "~/Themes/{0}.aspx",
                "~/Themes/{0}.ascx"
            };
            base.PartialViewLocationFormats = base.ViewLocationFormats;
            base.AreaPartialViewLocationFormats = base.AreaViewLocationFormats;

            this.membership = membership;
        }
    }
}
